package com.ytktt.study.week3.task346.gateway.properties;

import com.google.common.collect.Lists;
import com.ytktt.study.week3.task346.gateway.enums.RouterType;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

/**
 * 应用配置
 *
 * @author ytk
 */
@Getter
@Setter
@ConfigurationProperties(prefix = ApplicationProperties.PREFIX)
public class ApplicationProperties {

    public static final String PREFIX = "app";

    /**
     * 应用名称
     */
    private String name = "App";

    /**
     * 版本号
     */
    private String version = "1.0.0";

    /**
     * 端口
     */
    private int port = 8888;

    /**
     * 代理服务器的地址
     */
    private List<String> proxyServers = Lists.newArrayList();

    /**
     * inbound配置
     */
    private InBoundProperties inBound = new InBoundProperties();

    /**
     * 请求处理配置
     */
    private RequestProperties request = new RequestProperties();

    /**
     * 路由配置
     */
    private RouterProperties router = new RouterProperties();

    @Getter
    @Setter
    public static class InBoundProperties {

        public static final String PREFIX = "app.inbound";

        /**
         * 线程组管理boss线程数量
         */
        private int bossCount = 2;

        /**
         * 线程组管理worker线程数量
         */
        private int workerCount = 16;

        /**
         * TCP接收缓冲区(单位:K)
         */
        private int rcvBuf = 32;

        /**
         * TCP发送缓冲区(单位:K)
         */
        private int sndBuf = 32;

        /**
         * 是否禁用Nagle算法
         */
        private boolean tcpNoDelay = true;

        /**
         * 是否支持长连接
         */
        private boolean keepalived = true;

        /**
         * 是否重用地址
         */
        private boolean reuseAddr = true;

        /**
         * 是否重用端口
         */
        private boolean reusePort = true;
    }

    @Getter
    @Setter
    public static class RequestProperties {

        /**
         * 黑名单列表
         */
        private List<String> blackUrls = Lists.newArrayList();
    }

    @Getter
    @Setter
    public static class RouterProperties {

        public static final String PREFIX = "app.router";

        /**
         * 路由算法
         */
        private RouterType type = RouterType.RANDOM;
    }
}
